<?php
/**
 * Created by PhpStorm.
 * Script Name: MiniAppCode.php
 * Create: 10/15/23 5:40 PM
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\service;


use plugin\wechat\app\service\OpenPlatform as OpenPlatformService;

class MiniAppCode extends Mini
{

    /**
     * 生成带参二维码
     * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getQRCode.html
     * @param string $page
     * @param array $options
     * @param null $mp_info
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @return array|\EasyWeChat\Kernel\Support\Collection|mixed|object|\Psr\Http\Message\ResponseInterface|string
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function get($page = '', $options = [], $mp_info = null){
        $request = request();
        is_null($mp_info) && $mp_info = $request->miniInfo;
        $app = self::getApp($mp_info);
        if(empty($options)){
            $res = $app->app_code->get($page);
        }else{
            $res = $app->app_code->get($page, $options);
        }
        return $res;
    }

    /**
     * 获取无限制小程序码
     * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html
     * @param string $scene
     * @param array $options
     * @param null $mp_info
     * @return array|\EasyWeChat\Kernel\Support\Collection|mixed|object|\Psr\Http\Message\ResponseInterface|string
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    static function getUnlimit($scene = '', $options = [], $mp_info = null){
        $request = request();
        is_null($mp_info) && $mp_info = $request->miniInfo;
        $app = self::getApp($mp_info);
        if(empty($options)){
            $res = $app->app_code->getUnlimit($scene);
        }else{
            $res = $app->app_code->getUnlimit($scene, $options);
        }
        return $res;
    }
}